package com.bases {
	import com.bases.ScollBar.TBaseScrollBar;
	import com.bases.ScollBar.TTextFiledScrollBar;
	import com.debug.TDebug;
	import com.riaidea.richtextfield.RichTextField;
	import flash.geom.Rectangle;
	import flash.text.TextFormat;
	import org.bytearray.display.ScaleBitmap;

	public class TRichTextArea extends RichTextField {
		private var scroolBar:TTextFiledScrollBar;
		private var textFormat:TextFormat;

		public function TRichTextArea(width:Number, height:Number, type:String = DYNAMIC){
			super(width, height, type);
			//this.addChildAt(bg,0);
			textFormat = new TextFormat();
			textFormat.rightMargin = 15;
			this.textfield.defaultTextFormat = textFormat;
			scroolBar = new TTextFiledScrollBar(this.textfield);
			this.addChild(scroolBar);
			this.relayout();
			scroolBar.visible = false;
			this.textfield.border = true;
			this.textfield.background = true;
			textfield.borderColor = 0x9BB2DC;
		}

		override protected function relayout():void {
			super.relayout();
			this.scroolBar.setPos(this.textfield.width - TBaseScrollBar.BUTTON_WIDTH - 1, 0);
			this.scroolBar.setSize(20, this.textfield.height);
		}

		override public function set htmlText(value:String):void {
			this.textfield.htmlText = value;
			this.textfield.setTextFormat(textFormat);
		}

		public function set maxScroll(value:Boolean):void {
			this.textfield.scrollV = this.textfield.bottomScrollV;
			if (textfield.maxScrollV > 1)
				textfield.scrollV = textfield.maxScrollV;
		}

		override public function setSize(w:Number, h:Number):void {
			super.setSize(w, h);
			this.scroolBar.setPos(this.textfield.width - TBaseScrollBar.BUTTON_WIDTH - 1, 0);
			this.scroolBar.setSize(20, this.textfield.height);
//			this.scrollRect=new Rectangle(0,0,w,h+1);
		}

		override public function dispose():void {
			if (!this.isDispose){
				super.dispose();
				scroolBar.dispose();
				scroolBar = null;
				textFormat = null;
			}
		}
	}
}